/*
 * @Description  : 
 * @Version      : 1.0
 * @Author       : Shiming
 * @Date         : 2022-02-11 14:23:46
 * @LastEditors  : Shiming
 * @LastEditTime : 2022-02-11 14:29:00
 * @FilePath     : \\tms-obc-web\\src\\app\\shared\\components\\singlepage-setting\\singlepage-setting-h5\\singlepage-setting-h5.component.ts
 * Copyright (C) 2022 huzhenhong. All rights reserved.
 */
import { Component, OnInit, EventEmitter, Input, Output } from '@angular/core';
import { BaseService } from '@shared';

const JSONTYPE = new Set([5,6]);
@Component({
  selector: 'app-singlepage-setting-h5',
  templateUrl: './singlepage-setting-h5.component.html',
  styleUrls: ['./singlepage-setting-h5.component.less']
})
export class SinglepageSettingH5Component implements OnInit {
  @Input()
  tabs: any[] = [];
  @Input()
  selectedTab: any = null;

  @Input()
  configList: any = [];
  @Output()
  selectedEvent = new EventEmitter<any>();
  @Output()
  saveEvent = new EventEmitter<any>();

  @Input()
  tabSpan = 4;
  @Input()
  labelWidth = 250;
  @Input()
  itemValue = 'itemValue';

  constructor(public service: BaseService) {}

  ngOnInit() {}

  changeType(type: any): void {
    this.selectedTab = type;
    console.log(type);
    
    this.selectedEvent.emit(this.selectedTab);
  }

  saveAction() {
    if (this.configList?.length < 0) {
      return;
    }

    let params = [...this.configList];
    params = params.map((item: any) => {
      if (JSONTYPE.has(item.itemType)) {
        item.itemValue = item.itemValue ? JSON.stringify(item.itemValue) : null;
      }
      return {
        ...item,
        remark: item.remark ? JSON.stringify(item.remark) : null,
        itemData: item.itemData ? JSON.stringify(item.itemData) : null
      };
    });
    this.saveEvent.emit(params);
  }
}
